package com.ymtms.arrivalofgoods.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ymtms.arrivalofgoods.anotation.Syslog;
import com.ymtms.arrivalofgoods.bo.SyslogBO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

@Slf4j
@Service
public class SyslogServiceImpl {


    public boolean save(SyslogBO syslogBO) {
        //System.out.println(syslogBO);
        saveLogToFile("e://logger",syslogBO);
        log.info(syslogBO.getParams());
        return true;
    }


    public void saveLogToFile(String filePath, SyslogBO syslogBO){

        File file=new File(filePath);

        if (!file.exists()){
            file.listFiles();
        }
        BufferedWriter bw=null;
        try {
             bw=new BufferedWriter(new FileWriter(file));
            bw.write(syslogBO.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (bw!=null){
                try {
                    bw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }

}
